<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="complainDisposeProportion" id="complainDisposeProportion"></div>
    <div class="mod-demo__dhcomplaininfo}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.id" placeholder="根据投诉编号进行查询" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="getDataList()"></el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('demo:dhcomplaininfo:delete')" type="danger" icon="el-icon-delete"
                     @click="deleteHandle()"></el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle"
                style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50px"></el-table-column>
        <el-table-column prop="id" label="投诉编号" header-align="center" align="center"></el-table-column>
        <el-table-column prop="userId" label="投诉人账号" header-align="center" align="center"></el-table-column>
        <el-table-column prop="complainTime" label="投诉时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="problem" label="问题描述" header-align="center" align="center"></el-table-column>
        <el-table-column prop="disposeStatus" label="处理状态" header-align="center" align="center">
          <template slot-scope="scope">
            <p>{{ scope.row.disposeStatus == 1 ? '已完成处理' : ' 未处理' }}</p>
          </template>
        </el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-show="scope.row.disposeStatus == 0" type="success" size="small" icon="el-icon-finished"
                       @click="disposeComplain(scope.row.id)">{{ '处理投诉' }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './dhcomplaininfo-add-or-update'
import * as echarts from "echarts";

export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/demo/dhcomplaininfo/page',
        getDataListIsPage: true,
        exportURL: '/demo/dhcomplaininfo/export',
        deleteURL: '/demo/dhcomplaininfo',
        deleteIsBatch: true
      },
      dataForm: {
        id: ''
      },
      ComplainDisposeProportionPieData: [
        {value: '', name: '已处理'},
        {value: '', name: '未处理'}
      ]
    }
  },
  components: {
    AddOrUpdate
  },
  created() {
    this.setComplainDisposeProportionPieData();
  },
  methods: {
    /**
     * 确认用户的投诉已被处理此条
     * @param id
     */
    disposeComplain(id) {
      this.$confirm('确认已处理此条投诉？', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.get('demo/dhcomplaininfo/disposeComplain/' + id)
            .then(({data: res}) => {
              this.query();
              this.setComplainDisposeProportionPieData();
              this.$message({
                type: 'success',
                message: '操作成功！'
              })
            })
      })
    },
    /**
     * 投诉处理与未处理比例可视化图形初始化方法
     */
    echartsComplainDisposeProportion() {
      echarts.init(document.getElementById('complainDisposeProportion')).setOption({
        title: {
          text: '投诉已处理、未处理比例'
        },
        tooltip: {
          trigger: 'item'
        },
        series: [
          {
            type: 'pie',
            radius: '50%',
            data: this.ComplainDisposeProportionPieData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      })
    },
    /**
     * 获取投诉处理与未处理比例可视化图形数据
     */
    setComplainDisposeProportionPieData() {
      this.$http.get('demo/dhcomplaininfo/setComplainDisposeProportionPieData')
          .then(({data: res}) => {
            this.ComplainDisposeProportionPieData[0].value = res.data[0];
            this.ComplainDisposeProportionPieData[1].value = res.data[1];
            this.echartsComplainDisposeProportion();
          }).catch(_ => {
      })
    }
  }
}
</script>

<style scoped>
.complainDisposeProportion {
  width: 400px;
  height: 300px;
}
</style>
